<link rel="stylesheet" href="../public/js/vendor/laydate/need/laydate.css">
<link rel="stylesheet" href="../public/js/vendor/laydate/skins/default/laydate.css">
<script src="../public/js/vendor/laydate/laydate.js"></script>
<link rel="stylesheet" href="../public/js/vendor/uploadify/mydemo/uploadify-demo.css">
<script src="../public/js/vendor/uploadify/jquery.uploadify.min.js"></script>
<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i> 冰鲜供应详情</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-horizontal" role="form" method="post" action="" data-validate="validate">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">标题</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="" name="title" value="" disabled>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">发布者信息</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="" name="user_phone" value="" readonly>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="title_bar">鱼货信息</div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">鱼货信息</label>
                                            <div class="col-sm-4">
                                                <div class="panel panel-default" >
                                                    <div class="panel-body" id="fish_content"></div>
                                                </div>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">发布时间:</label>
                                            <div class="col-sm-4">
                                                <div class="form-group">
                                                    <input type="text" class="form-control" name="displayTime" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" value=""/>
                                                </div>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">到港时间:</label>
                                            <div class="col-sm-4">

                                                <div class="form-group">
                                                    <input type="text" class="form-control" name="arrivalTime" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" value=""/>
                                                </div>

                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">图片:</label>
                                            <div class="col-sm-4">
                                                <input type="button" id="uploadify1"/>

                                                <div class="upload-img-box">

                                                </div>
                                            </div>
                                        </div>
                                        <hr/>


                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">备注</label>
                                            <div class="col-sm-10">
                                                <textarea class="form-control"  name="remark"></textarea>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">状态:</label>
                                            <div class="col-sm-4">
                                                <select class="form-control" name="state" id="state">
                                                    <option value="-2">请选择</option>
                                                    <option value="-1">审核失败</option>
                                                    <option value="0">未审核</option>
                                                    <option value="1">审核通过</option>
                                                    <option value="2">交易成功</option>
                                                </select>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <div class=" col-sm-12">
                                                <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
                                            </div>
                                        </div>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>



<script>
    function validate($from) {
//        var title = $from.find('input[name="title"]');
//        if ($.trim(title.val()) == '') {
//            return '新闻标题不能为空';
//        }
        return true;
    }

    $(document).ready(function () {

        $("form").attr("action", common_conf.requestUrl+'osupply/edit');

//       getSupplyDetail($("#editid").val());
        getOSupplyDetail($.getUrlVar('id'));
        initPicUploadComponet();
    });


    function getOSupplyDetail(id) {
        $.ajax({
            type: 'post',
            url: common_conf.requestUrl+'osupply/detail',
            contentType : 'application/json;charset=UTF-8',
            cache: false,
            data: '{"id":'+id+'}',
            dataType: 'json',
            beforeSend: function () {
            },
            success: function (returnData) {
                if(forceLogin(returnData)) return;
                var obj=returnData;
                if(obj.state=="success"){
                    initFormData(obj.data);
                }else{
                    alert("获取失败");
                }
            },
            error: function () {
                alert("未找到模板");
            }
        });
    }

    function initFormData($osupply) {
        $("input[name='title']").val($osupply.title);
        $("input[name='user_phone']").val($osupply.user_phone);
        var fishInfo=JSON.parse($osupply.fishInfo);
        var fish_spec="品类(规格)："+fishInfo.fishName+"("+fishInfo.specName+")<br />";
        var quantity="发布量："+$osupply.quantity+"<br />";
        var priceInfo="价格："+$osupply.priceInfo+"<br />";
        var placeObj=JSON.parse($osupply.tradePlace);
        var placeInfo="交易地点："+placeObj.townName+placeObj.dockName+"<br />";

        $("#fish_content").html(fish_spec+quantity+priceInfo+placeInfo+$osupply.attriButeStr);
        $("input[name='displayTime']").val($osupply.displayTime);
        $("input[name='arrivalTime']").val($osupply.arrivalTime);
        $("input[name='remark']").val($osupply.remark);
        $('form').append("<input type='hidden' name='id' value='"+$osupply.id+"'>");

        $("#state option[value='"+$osupply.state+"']").attr("selected","selected");

        if(""!=$osupply.images){
            var images=$osupply.images.split(",");
            displayImgs(images);
        }

    }



</script>